/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgSoul
    {
        private readonly Dictionary<int, CfgSoul> _dataMap;
        private readonly List<CfgSoul> _dataList;


        public TbCfgSoul(ByteBuf _buf)
        {
            //first read common data
            _TbCommonSoul _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonSoul(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgSoul>(size * 3 / 2);
            _dataList = new List<CfgSoul>(size);

            for (int i = 0; i < size; i++)
            {
                CfgSoul _v;
                _v = CfgSoul.DeserializeCfgSoul(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgSoul> DataMap => _dataMap;
        public IReadOnlyList<CfgSoul> DataList => _dataList;

        public CfgSoul Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgSoul] config not found,id:" + key.ToString());

            return null;
        }

        public CfgSoul GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "soul";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgSoul LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgSoul(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgSoul
    {
        private CfgSoul(ByteBuf _buf, _TbCommonSoul _commonData)
        {
            Id = _buf.ReadInt();
            Type = _buf.ReadInt();
            IsHide = _buf.ReadBool();
            { int dataIndex = _buf.ReadInt() - 1; SoulSkins = _commonData._field0[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; SoulSkins2 = _commonData._field1[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; HeroIds = _commonData._field2[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; BirthDay = _commonData._field3[dataIndex]; }
            BirthDayMail = _buf.ReadInt();
            HeroHeight = _buf.ReadFloat();
            HeroWeight = _buf.ReadFloat();

            PostInit();
        }

        internal static CfgSoul DeserializeCfgSoul(ByteBuf _buf, _TbCommonSoul _commonData)
        {
            return new CfgSoul(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 类型（0-主角；1-英雄）
        /// </summary>
        public int Type { get; private set; }
        /// <summary>
        /// 是否隐藏(0显示1隐藏）
        /// </summary>
        public bool IsHide { get; private set; }
        /// <summary>
        /// 灵魂皮肤(男)，第一个表默认皮肤
        /// </summary>
        public IReadOnlyList<int> SoulSkins { get; private set; }
        /// <summary>
        /// 灵魂皮肤
        /// </summary>
        public IReadOnlyList<int> SoulSkins2 { get; private set; }
        /// <summary>
        /// 关联英雄，第一个表默认
        /// </summary>
        public IReadOnlyList<int> HeroIds { get; private set; }
        /// <summary>
        /// 生日
        /// </summary>
        public string BirthDay { get; private set; }
        /// <summary>
        /// 生日邮件
        /// </summary>
        public int BirthDayMail { get; private set; }
        /// <summary>
        /// 身高
        /// </summary>
        public float HeroHeight { get; private set; }
        /// <summary>
        /// 体重
        /// </summary>
        public float HeroWeight { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonSoul
    {

        internal IReadOnlyList<IReadOnlyList<int>> _field0 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field1 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field2 { get; private set; }
        internal IReadOnlyList<string> _field3 { get; private set; }
        internal _TbCommonSoul(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field2 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field3 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
        }

    }
}
